home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
386
/
utility
/
speed_1.s
< prev
next >
Wrap
Text File
|
1985-11-19
|
15KB
|
314 lines
; Program Name: SPEED_1.S
; Version: 1.006
; Assembly Instructions:
; Assemble in "PC-relative" mode and save with a TTP extension.
; Execution Instructions:
; SPEED_1.TTP will not execute unless the custom traps in program
; TRAPS.PRG and TRAP_9.PRG have previously been installed. The custom
; traps are installed when those programs are executed from the desktop
; or from an AUTO folder on a boot disk.
; NOTE: The time required for a program to be loaded into memory depends
; on the assembly mode used to assemble the program. This will be
; shown, using SPEEDTST.TTP, in chapter 5.
; In addition, a program's load time depends on the drive from which
; the program is loaded, the method used to format the disk on which
; the program is located, the position of the program on the disk
; and, in this case, the position of the child process relative to the
; position of the parent process.
; To eliminate the drive-variables when comparing the load and
; execution times of one program to that of another, the parent and
; the child should be isolated to an otherwise empty partition or
; floppy disk for each spawning instance.
; For example, if there are two programs involved in the comparison,
; first copy the parent, which is SPEED_1 in this case, so that it is
; the only item in the hard disk partition or on the floppy. Then,
; copy the first program to the same partition or floppy. Execute
; the parent, SPEED_1 in this case, and obtain the results.
; Remove the first program and copy the second. Execute the parent
; and obtain the results for the second program.
; Execute from the desktop. Type the name of an executable file which
; has a TOS or PRG extension on SPEED_1.TTP's input parameter line. The
; name of the program you type on the parameter line must be in the same
; directory as is SPEED_1.TTP and the program must be one that terminates
; with GEMDOS function $4C.
; Upon termination, the spawned program must return the value that is in
; memory location $4BA immediately after it has been loaded, hereafter called
; the after-load time or after-load value. Custom trap #3 (get_time) can be
; used to obtain that value. SPEED_1.TTP uses the value returned in D0 to
; calculate the spawned program's load and execution times.
; The spawned program must terminate with GEMDOS function $4C so that
; the after-load value can be returned in D0 by that function. The value
; returned in D0 by GEMDOS function $4C is limited to a 16 bit value.
; If the spawned program has any halt or wait instructions, such as wait
; for a keypress, etc., those should be commented out, then the program
; should be assembled especially for the speed test. Otherwise the
; execution time will include the time waiting for input.
; If custom trap #8 is used to terminate the program, the trap will
; execute a wait_for_keypress algorithm when the program is executed from
; the desktop, but it will omit the wait algorithm when the program is
; spawned by SPEED_1.TTP. In addition, trap #8 will return the after-load
; value to SPEED_1.TTP and terminate the spawned program with GEMDOS function
; $4C.
; Both trap #8 and SPEED_1.TTP require that the spawned program be
; initialized with custom trap #6. See the note in the data section, below.
; Primary Function:
; Spawn a process. Calculate the spawned program's load and execution
; times. Store these values in a disk file that is identified by the name
; of the spawned process with a DAT suffix.
; If the spawned process directs output to the screen, store that output
; in the same disk file. Note: only screen directed output processed by
; GEMDOS function $9 will be directed to the file. If BIOS function $3 is
; used for screen output, that output will not be redirected to the file.
; Secondary Function:
; Verify that trap #6 is resident and functions correctly. SPEED_1
; confirms that because it will not be able to spawn a process unless
; the trap #6 call has returned excess memory to the system.
; Description:
; SPEED_1 is the first in a series of programs which progress in
; algorithmic perfection until the program SPEEDTST is developed. Using
; this series of programs, I intend to help you experience selected stages
; of a program development process.
; The primary attribute of this development process is its dependence,
; during the early stages of development, on familiar documented algorithms
; that can easily be found in references for many programming languages.
; After a working model has been developed with these familiar algorithms,
; attempts are made to introduce unfamiliar algorithms which may be faster
; or consume less memory.
release_excess_memory:
lea program_end, a0 ; Put "end of program" address in A0.
movea.l 4(a7), a1 ; Put "basepage" address in A1.
movea.l a1, a4 ; Copy to A4 for command line access.
trap #6 ; Calculate program size and release memory.
; NOTE: A local stack is not declared in PRG_5AP.TOS. Because of the long
; string that is printed by that program, this program will bomb when
; it spawns PRG_5AP.TOS, if a local stack is not declared here.
lea stack, a7 ; Point A7 to this program's stack.
; The next task to be accomplished is an initialization algorithm. The
; name of the program that is to be typed on SPEED_1.TTP's input parameter
; line must be used in several ways. First, its suffix must be changed to
; DAT so that it can be passed as a NULL terminated string when GEMDOS $3C
; is invoked to create the disk file.
; Then it must be passed as a NULL terminated string with the program's
; original suffix when GEMDOS $4B is invoked to spawn the program.
; Finally, the program's name is used as part of SPEED_1.TTP's output
; header.
; The command line processing algorithm creates the required NULL terminated
; strings, storing them in locations declared in the data section of SPEED_1.
process_command_line_parameters:
lea $80(a4), a4 ; Fetch address of parameters.
move.b (a4)+, d0 ; Fetch parameter line character count.
lea program_name, a3 ; Load program_name address in A3.
subq.b #1, d0 ; Set up counter.
ext.w d0 ; Extend to match the size of the dbra
; instruction.
; NOTE: The dbcc instruction operates on a word length value, therefore,
; the value in the register that is to be decremented by a dbcc
; instruction must be placed there with a word size instruction, such
; as move.w #10, D0; or with a longword size instruction, as long as
; the value in the longword is limited to word size validity, or with
; a byte size instruction, as long as the value in the register is
; sign extended to word size, as is done in the instruction above.
fetch_character:
move.b (a4)+, (a3)+ ; Store character.
dbra d0, fetch_character ; Loop until d0 becomes negative.
move.b #0, (a3) ; Finish with a NULL.
create_file_name: ; Create a file to accept standard output.
lea filename, a4
lea program_name, a3
copy_name:
move.b (a3)+, (a4)+
cmpi.b #$2E, (a3) ; Is next byte of program_name the period?
bne.s copy_name ; Continue looping until period is seen.
move.b #$2E, (a4)+ ; Add a period.
move.b #$44, (a4)+ ; Add letter 'D'.
move.b #$41, (a4)+ ; Add letter 'A'.
move.b #$54, (a4)+ ; Add letter 'T'.
move.b #0, (a4) ; Add a NULL.
create_file:
move.w #0, -(sp) ; File attribute = read/write.
pea filename ; Will be name of spawned process + .DAT.
move.w #$3C, -(sp) ; Function = f_create = GEMDOS $3C.
trap #1 ; File handle is returned in D0.
addq.l #8, sp
lea file_handle, a0 ; Store returned file handle.
move.w d0, (a0)
redirect_output: ; Exchange file handle with screen's handle.
move.w file_handle, -(sp) ; This is the disk file's handle.
move.w #1, -(sp) ; This is the video screen's handle.
move.w #$46, -(sp) ; Function = f_force = GEMDOS $46.
trap #1
addq.l #6, sp
get_start_time:
lea start_time, a3 ; Fetch address of variable "start_time".
trap #3 ; Returns value of system clock in D0.
move.w d0, (a3) ; Save start time.
load_and_execute_program:
pea environ_string
pea command_line
pea program_name
move.w #0, -(sp)
move.w #$4B, -(sp) ; Function = GEMDOS $4B = p_exec.
trap #1
move.w d0, d3 ; Copy after-load value to D3 for calculation.
get_end_time:
trap #3 ; Returns value of system clock in D0.
move.w d0, d5 ; Copy to D5 for calculation.
sub.w d3, d5 ; Subtract after-load time from end time.
ext.l d5 ; Extend to 32 bits.
; NOTE: D5 now contains the spawned program's execution time, but the time
; has not yet been converted to milliseconds. See the note below
; concerning the sign extension of D3 and D5.
reposition_stack_pointer:
lea $10(sp), sp
; Note the difference between the use of GEMDOS function $19 below and
; the way it is used on page 116 of the Internals book. In the
; Internals book there are two errors: (1) sp should not be referenced
; indirectly, as (sp); (2) the ASCII code for the letter A should be
; added to the contents of the register--in the internals book the
; contents of the register are added to the ASCII code for the letter
; A.
get_drive:
move.w #$19, -(sp) ; Function = dgetdrv = GEMDOS $19.
trap #1 ; Returns 0 for drive A, 1 for B, etc.
addq.l #2, sp
add.b #$41, d0 ; Add ASCII value for A to compute ASCII
lea drive, a0 ; letter code for the drive value returned.
move.b d0, (a0) ; Save drive's ASCII letter code.
print_heading:
lea heading, a0
bsr print_string
lea program_name, a0
bsr print_string
print_drive_for_spawned_program:
lea drive_msg, a0
bsr print_string
compute_load_time:
lea load_time_msg, a0
bsr.s print_string
lea start_time, a3
sub.w (a3), d3 ; Subtract start time from after-load time.
ext.l d3 ; Extent to 32 bits.
; SIGN EXTENSION NOTE
; The value in D3, above, and in D5 previously, is extended to 32 bits
; because, although the number of 200hz intervals we are able to utilize is
; limited to a word size by the value that is returned in D0 via GEMDOS
; function $4C, the time converted to milliseconds can extend beyond that
; word size limitation.
trap #9 ; See description in TRAP_9.S.
close_file:
move.w file_handle, -(sp)
move.w #$3E, -(sp) ; Function = fclose = GEMDOS $3E.
trap #1
addq.l #4, sp
terminate:
move.w #0, -(sp)
trap #1
print_string: ; Expects address of string to be in A0.
pea (a0) ; Push address of string onto stack.
move.w #9, -(sp) ; Function = c_conws = GEMDOS $9.
trap #1 ; GEMDOS call
addq.l #6, sp ; Reset stack pointer to top of stack.
rts
data
heading: dc.b $D,$A,"SPEED_1.TTP Execution Results",$D,$A
dc.b "for ",0
drive_msg: dc.b ", loaded from drive: "
drive: dc.b "A",$D,$A,0
load_time_msg: dc.b $D,$A," Load time: ",0
; NOTE: Custom trap #6 checks the environmental string pointer of each
; program that invokes it to see if the pointer contains the address
; of the label "environ_string" below. That test is performed by
; comparing the contents of the address contained in the pointer to
; the ASCII string "TERM" declared below.
; When a match occurs, it means that the program invoking trap #6 has
; been spawned by SPEED_1 (or by a similar program), therefore, trap
; #6 sets the value of the boolean variable "spawned", declared by
; TRAPS.PRG, to all ones = true.
; When custom trap #8 is invoked by a program, the state of the
; variable "spawned" is tested. If the state is true, the program
; invoking custom trap #8 is terminated with GEMDOS function $4C and
; the after-load time, which was saved by custom trap #6, is returned
; to the parent program.
; If the state of "spawned" is false, GEMDOS function $8 is executed
; so that execution will pause for a keypress. When the keypress is
; received, GEMDOS function $0 is executed.
; In this manner, custom trap #8, working in conjunction with custom
; trap #6, eliminates the "wait for keypress" algorithm automatically
; when a program is spawned by SPEED_1 (or a similar program). This
; prevents the computed execution time from being corrupted by a time
; period that involves a wait for keyboard input.
environ_string: dc.b "TERM",0
command_line: dc.b 0
align
bss
start_time: ds.w 1 ; Value in $4BA just before spawning.
file_handle: ds.w 1 ; Handle for the filename below.
filename: ds.l 4 ; File name for execution results.
program_name: ds.l 4 ; Filename buffer. Must be NULL terminated.
ds.l 96 ; Program stack.
stack: ds.l 0 ; Address of program stack.
program_end: ds.l 0
end